#include "reserveannouncement.h"
#include "ui_reserveannouncement.h"
#include "reservehome.h"
#include "announcement.h"
#include "QMouseEvent"
reserveAnnouncement::reserveAnnouncement(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::reserveAnnouncement)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint); // 设置窗口无边框
}

reserveAnnouncement::~reserveAnnouncement()
{
    delete ui;
}

void reserveAnnouncement::setContent(QString content){
    ui->label->setText(content);
    // 设置文本对齐方式
    ui->label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
    // 设置样式表，包括字体大小、颜色、行高等
    ui->label->setStyleSheet("QLabel {"
                             "font-size: 40px;"  // 字体大小
                             "color: black;"     // 字体颜色
                             "line-height: 3;" // 行高，增加行间距
                             "margin: 10px;"     // 边距
                             "padding: 10px;"    // 内边距
                             "}");

    // 启用自动换行
    ui->label->setWordWrap(true);
}

void reserveAnnouncement::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
                initialMousePosition = event->globalPos(); // 记录鼠标按下时的全局位置
                isDragging = true; // 开始拖动
            }
    }

void reserveAnnouncement::mouseMoveEvent(QMouseEvent *event){
    if (isDragging && event->buttons() & Qt::LeftButton) {
                QPoint delta = event->globalPos() - initialMousePosition; // 计算鼠标移动的距离
                move(x() + delta.x(), y() + delta.y()); // 根据鼠标移动的距离来移动窗口
                initialMousePosition = event->globalPos(); // 更新鼠标位置
            }
    }
void reserveAnnouncement::mouseReleaseEvent(QMouseEvent *event) {
        if (event->button() == Qt::LeftButton) {
            isDragging = false; // 结束拖动
        }
    }


void reserveAnnouncement::on_pushButton_2_clicked()
{
    this->close();
    if(reserveHome::announcementIsHome){
        reserveHome* r=new reserveHome;
        r->show();
    }else {
        announcement* a = new announcement;
        a->show();
    }
}
